package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    /**
     * 通过电话号码查询是否为会员
     * @param telephone
     * @return
     */
    @Override
    public Member findByTelephone(String telephone) {

        return memberDao.findByTelephone(telephone);
    }

    /**
     * 添加会员
     * @param member
     */
    @Override
    public void add(Member member) {

        memberDao.add(member);
    }

    /**
     * 统计过去一年的会员数量
     * @param mouths
     * @return
     */
    @Override
    public List<Integer> getMemberReport(List<String> mouths) {

        //创建数组
        List<Integer> memberCount = new ArrayList<>();

        //进行循环
        for (String mouth : mouths) {

            //将月份进行拼接
            mouth+="-31";

            //查询到这个month为，一会有多少个会员
            Integer count = memberDao.findMemberCountBeforeDate(mouth);

            //添加进数组
            memberCount.add(count);

        }

        return memberCount;
    }
}
